﻿-- =============================================
-- Script Template
-- =============================================
USE [DB_Ex]
GO

/****** Object:  View [dbo].[vw_1C_Users_Moving]    Script Date: 12/05/2011 10:23:51 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

/*
JobType -
совместитель - 0 ; основное место работы - 1;
*/
CREATE VIEW [dbo].[vw_1C_Users_Moving]
AS
SELECT     Worker._Period AS DT, ChangeType._EnumOrder AS Type, 
                      CASE WHEN ChangeType._EnumOrder = 0 THEN 'прием на работу' ELSE (CASE WHEN ChangeType._EnumOrder = 1 THEN 'внутреннее перемещение' ELSE 'увольнение'
                       END) END AS TypeName, ChangeType._IDRRef, WorkerOffice._Code AS TabNum, WorkerOffice._IDRRef AS ID, FIOActual.LastName, FIOActual.FirstName, 
                      FIOActual.Otchestvo, Professional._Description AS Profesional, Departments._Description AS Department, WorkSchedule._Description AS Uslovie, 
                      CASE WHEN Worker._Fld5085 = 1 THEN 1 ELSE 0 END AS JobType, 
                      CASE WHEN Worker._Fld5085 = 1 THEN 'основное место работы' ELSE 'совместитель' END AS JobTypeName
FROM         DB01.Zar_kor_81.dbo._InfoRg5080 AS Worker LEFT OUTER JOIN
                      DB01.Zar_kor_81.dbo._Reference84 AS WorkerOffice LEFT OUTER JOIN
                      DB01.Zar_kor_81.dbo._Reference101 AS FizichjeskieLica LEFT OUTER JOIN
                          (SELECT     LastName, FirstName, Otchestvo, Period, FizLico
                            FROM          dbo.vw_1C_FizFace) AS FIOActual ON FizichjeskieLica._IDRRef = FIOActual.FizLico ON 
                      WorkerOffice._Fld993RRef = FizichjeskieLica._IDRRef LEFT OUTER JOIN
                      DB01.Zar_kor_81.dbo._Reference28 AS WorkSchedule ON WorkerOffice._Fld1001RRef = WorkSchedule._IDRRef ON 
                      Worker._Fld5081RRef = WorkerOffice._IDRRef LEFT OUTER JOIN
                      DB01.Zar_kor_81.dbo._Enum285 AS ChangeType ON Worker._Fld5096RRef = ChangeType._IDRRef LEFT OUTER JOIN
                      DB01.Zar_kor_81.dbo._Reference38 AS Professional ON Worker._Fld5088RRef = Professional._IDRRef LEFT OUTER JOIN
                      DB01.Zar_kor_81.dbo._Reference67 AS Departments ON Worker._Fld5087RRef = Departments._IDRRef

GO

EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[22] 4[15] 2[20] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "Worker"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 114
               Right = 199
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "WorkerOffice"
            Begin Extent = 
               Top = 6
               Left = 237
               Bottom = 114
               Right = 390
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "FizichjeskieLica"
            Begin Extent = 
               Top = 6
               Left = 428
               Bottom = 114
               Right = 581
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "FIOActual"
            Begin Extent = 
               Top = 114
               Left = 38
               Bottom = 222
               Right = 189
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "WorkSchedule"
            Begin Extent = 
               Top = 114
               Left = 227
               Bottom = 222
               Right = 378
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "ChangeType"
            Begin Extent = 
               Top = 114
               Left = 416
               Bottom = 192
               Right = 567
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "Professional"
            Begin Extent = 
               Top = 192
               Left = 416
               Bottom = 300
               Right = 567
            End
    ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'vw_1C_Users_Moving'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane2', @value=N'        DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "Departments"
            Begin Extent = 
               Top = 222
               Left = 38
               Bottom = 330
               Right = 191
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 15
         Width = 284
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 2460
         Width = 2205
         Width = 2715
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 1440
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'vw_1C_Users_Moving'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=2 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'vw_1C_Users_Moving'
GO


